<?php
function kieuanh($path)
{
	$ext = substr($path, strlen($path)-4);
	if($ext == '.swf')
		return 1;
	else
		return 0;
}
function dinhdangtien($n)
{
	$temp = (string)$n;
	$r = "";
	while(strlen($temp) > 3)
	{
		$r = substr($temp, strlen($temp)-3) . "." . $r;
		$temp = substr($temp, 0, strlen($temp)-3);
	}
	$r = $temp . "." . $r;
	return substr($r, 0, strlen($r)-1);
}
function cstr($text, $start=0, $limit=12)
    {
        if (function_exists('mb_substr')) {
            $more = (mb_strlen($text) > $limit) ? TRUE : FALSE;
            $text = mb_substr($text, 0, $limit, 'UTF-8');
            return array($text, $more);
        } elseif (function_exists('iconv_substr')) {
            $more = (iconv_strlen($text) > $limit) ? TRUE : FALSE;
            $text = iconv_substr($text, 0, $limit, 'UTF-8');
            return array($text, $more);
        } else {
            preg_match_all("/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/", $text, $ar);   
            if(func_num_args() >= 3) {   
                if (count($ar[0])>$limit) {
                    $more = TRUE;
                    $text = join("",array_slice($ar[0],0,$limit))."..."; 
                }
                $more = TRUE;
                $text = join("",array_slice($ar[0],0,$limit)); 
            } else {
                $more = FALSE;
                $text =  join("",array_slice($ar[0],0)); 
            }
            return array($text, $more);
        } 
}

function _substr($text, $limit=25)
{
    $val = cstr($text, 0, $limit);
    return $val[1] ? $val[0]."..." : $val[0];
}  

function _catchuoi($str='', $limit=40){
	$temp = split(' ', strip_tags($str));
	$temp = str_replace("\n", ' ', $temp);
	$temp = str_replace('"', '\"', $temp);
	$temp = str_replace("'", '&acute;', $temp);
	$string = '';
	for($j=0; $j<$limit && $j < count($temp); $j++){
		//echo $temp[$j] . ' ';
		$string = $string.$temp[$j].' ';
	}
	$string = $string.'...';
//	echo '...';
	return $string;
}

function ngaythang($ngaythang)
{
	$temp = split(' ', $ngaythang);
	$temp1 = split('-', $temp[0]);
	$r = $temp1[2] . '-' . $temp1[1] . '-' . $temp1[0];
	return $r;
}
function lasonguyen($value)
{
	$a = (int)$value;
	if((string)$a == $value)
		return TRUE;
	else
		return FALSE;
}
//Get anh tu thumbnail
function get_thumbnail($path){
	//Sunset2_thumb.jpg
	$ext = substr($path, strlen($path)-4);//.jpg, .gif
	
	$ten = substr($path,0,strlen($path)-4);
	
	
	return $ten.'_thumb'.$ext;
}
function get_anhtu_thumbnail($path){
	//Sunset2_thumb.jpg
	$ext = substr($path, strlen($path)-4);
	$ten = substr($path,0,strlen($path)-10);
	return $ten.$ext;
}

function tienbangchu($val)
{
	$ti = (int)($val / 1000000000);
	$trieu = (int)(($val - $ti * 1000000000)/1000000);
	$nghin = (int)(($val - $ti * 1000000000 - $trieu * 1000000)/1000);
	$dv = (int)(($val - $ti *1000000000) % 1000);
	$ret = '';
	if($ti > 0)
		$ret .= $ti . ' tỷ ';
	if($trieu > 0)
		$ret .= $trieu . ' triệu ';
	if($nghin > 0)
		$ret .= $nghin . ' nghìn ';
	if ($dv > 0)
		$ret .= $dv . ' ';
	return $ret;
}
function bodautiengviet($str)
{
	$marTViet=array("à","á","ạ","ả","ã","â","ầ","ấ","ậ","ẩ","ẫ","ă",
					"ằ","ắ","ặ","ẳ","ẵ","è","é","ẹ","ẻ","ẽ","ê","ề"
					,"ế","ệ","ể","ễ",
					"ì","í","ị","ỉ","ĩ",
					"ò","ó","ọ","ỏ","õ","ô","ồ","ố","ộ","ổ","ỗ","ơ"
					,"ờ","ớ","ợ","ở","ỡ",
					"ù","ú","ụ","ủ","ũ","ư","ừ","ứ","ự","ử","ữ",
					"ỳ","ý","ỵ","ỷ","ỹ",
					"đ",
					"À","Á","Ạ","Ả","Ã","Â","Ầ","Ấ","Ậ","Ẩ","Ẫ","Ă"
					,"Ằ","Ắ","Ặ","Ẳ","Ẵ",
					"È","É","Ẹ","Ẻ","Ẽ","Ê","Ề","Ế","Ệ","Ể","Ễ",
					"Ì","Í","Ị","Ỉ","Ĩ",
					"Ò","Ó","Ọ","Ỏ","Õ","Ô","Ồ","Ố","Ộ","Ổ","Ỗ","Ơ"
					,"Ờ","Ớ","Ợ","Ở","Ỡ",
					"Ù","Ú","Ụ","Ủ","Ũ","Ư","Ừ","Ứ","Ự","Ử","Ữ",
					"Ỳ","Ý","Ỵ","Ỷ","Ỹ",
					"Đ");

$marKoDau=array("a","a","a","a","a","a","a","a","a","a","a"
				,"a","a","a","a","a","a",
				"e","e","e","e","e","e","e","e","e","e","e",
				"i","i","i","i","i",
				"o","o","o","o","o","o","o","o","o","o","o","o"
				,"o","o","o","o","o",
				"u","u","u","u","u","u","u","u","u","u","u",
				"y","y","y","y","y",
				"d",
				"A","A","A","A","A","A","A","A","A","A","A","A"
				,"A","A","A","A","A",
				"E","E","E","E","E","E","E","E","E","E","E",
				"I","I","I","I","I",
				"O","O","O","O","O","O","O","O","O","O","O","O"
				,"O","O","O","O","O",
				"U","U","U","U","U","U","U","U","U","U","U",
				"Y","Y","Y","Y","Y",
				"D");
$temp = str_replace($marTViet, $marKoDau, $str);
$temp = str_replace(array(',',';','\'','"','(',')','[',']','|','\\',"/","!","@","$","^","&","*","+","=","<",">","–", '™', '®', '%'), '-', $temp);
$temp = str_replace(' ', ' ', $temp);
while(strpos($temp, '--') > 0)
	$temp = str_replace('--', '-', $temp);
while(strpos($temp, '--') === 0)
	$temp = str_replace('--', '-', $temp);
return $temp;
}
?>